﻿var xmlHttp=null;  
 var str =""; 
 function init_simplecomment()  
 {  
     if(window.XMLHttpRequest)  
       {  
        xmlHttp=new XMLHttpRequest();  

       }  
     else if(window.ActiveXObject)  
       {  
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
       }  
       xmlHttp.onreadystatechange=callBack;  
       xmlHttp.open("GET","/data.xml",true);  
       //xmlHttp.open("GET","http://staff.ustc.edu.cn/~mengning/test/data.xml",false); 
       xmlHttp.send(null);  
 } 
 function callBack()  
 {  
	
         if(xmlHttp.readyState==4)  
         {  
             if(xmlHttp.status==200)  
             {               	
	             var xmlDOM=xmlHttp.responseXML;  
	             var xmlRoot=xmlDOM.documentElement;  
	             var sortField=xmlRoot.selectNodes("/commentlist/comment"); 
	             var j=0; 
	                
	             //var oTest = document.getElementById("SimpleComment"); 
	             str+=" <div id=\"SimpleComment\">  ";
		           /* Output SimpleComment title */
		           str+=" <h1> ";
	             str+=" <span>相关评论 by <a href=\"http://52simplecomment.appspot.com\" target=\"_blank\">SimpleComment</a></span> ";	 			
	             str+=" <span id=\"add_label\"><a href=\"javascript:void(0);\" onclick=\"textareaFocus();\">添加评论</a></span> ";
	             str+=" <span id=\"admin_label\"><a href=\"http://52simplecomment.appspot.com/admin\" target=\"_blank\">管理评论</a></span> ";
	             str+=" </h1> ";			
	             /* Output comment list */
	             str+=" <ul> ";
	             for(var i=0;i<sortField.length;i++) 
	             { 
	                  for(j=0;j<sortField[i].childNodes.length;j++) 
	                  { 
	                       
	                      str+=" <li> <h4> ";					
			                  str+=" <span class=\"author\">" + sortField[i].childNodes[j].text + "</span> "; 
	                      str+=" <span class=\"date\">" + "     发布于 "+sortField[i].childNodes[++j].text+"</span>"; 
	                      str+=" </h4>";  
	                      str+=" <p class=\"content\">"+sortField[i].childNodes[++j].text+" </p>"; 
	                      str+=" </li>"; 
	                       
	                  }     
	             } 
	             str+=" </ul> "; 
	             /* Output SimpleComment POST form */ 
	             str+=" <form action=\"/sign\" method=\"post\"> ";
               str+=" <div><textarea name=\"content\" rows=\"6\" cols=\"120\"></textarea></div> ";
               str+=" <div><input type=\"submit\" value=\"Sign Guestbook\"></div> ";
               str+=" </form>   "; 
               str+=" </div>";  
               document.write(str);     
	             //oTest.innerHTML+=str;                                                      
             }      
         } 
           

 }  

 